CREATE TABLE [dbo].[DnnProduct_ModulePermission]
(
[ModulePermissionID] [int] NOT NULL IDENTITY(1, 1),
[ModuleID] [int] NOT NULL,
[PermissionID] [int] NOT NULL,
[AllowAccess] [bit] NOT NULL,
[RoleID] [int] NULL,
[UserID] [int] NULL,
[CreatedByUserID] [int] NULL,
[CreatedOnDate] [datetime] NULL,
[LastModifiedByUserID] [int] NULL,
[LastModifiedOnDate] [datetime] NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_ModulePermission] ADD CONSTRAINT [PK_DnnProduct_ModulePermission] PRIMARY KEY CLUSTERED  ([ModulePermissionID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_ModulePermission] ADD CONSTRAINT [IX_DnnProduct_ModulePermission] UNIQUE NONCLUSTERED  ([ModuleID], [PermissionID], [RoleID], [UserID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_ModulePermission_Permission] ON [dbo].[DnnProduct_ModulePermission] ([PermissionID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_ModulePermission_Roles] ON [dbo].[DnnProduct_ModulePermission] ([RoleID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_DnnProduct_ModulePermission_Users] ON [dbo].[DnnProduct_ModulePermission] ([UserID]) WITH (FILLFACTOR=85) ON [PRIMARY]
GO
ALTER TABLE [dbo].[DnnProduct_ModulePermission] ADD CONSTRAINT [FK_DnnProduct_ModulePermission_DnnProduct_Modules] FOREIGN KEY ([ModuleID]) REFERENCES [dbo].[DnnProduct_Modules] ([ModuleID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[DnnProduct_ModulePermission] WITH NOCHECK ADD CONSTRAINT [FK_DnnProduct_ModulePermission_DnnProduct_Permission] FOREIGN KEY ([PermissionID]) REFERENCES [dbo].[DnnProduct_Permission] ([PermissionID]) ON DELETE CASCADE
GO
ALTER TABLE [dbo].[DnnProduct_ModulePermission] WITH NOCHECK ADD CONSTRAINT [FK_DnnProduct_ModulePermissionDnnProduct_Users] FOREIGN KEY ([UserID]) REFERENCES [dbo].[DnnProduct_Users] ([UserID]) NOT FOR REPLICATION
GO
